class BarCoworker < ActiveRecord::Base
  belongs_to :bar
  belongs_to :user
  
  validates_presence_of :user_id
  validates_presence_of :bar_id
  
  def self.add(bar_id, user_id)
    # first check for duplictate
    duplicate = find(:all, :conditions => ["bar_id = ? and user_id = ?", 
                                           bar_id, user_id])
    if duplicate.blank?                                       
      coworker         = BarCoworker.new
      coworker.bar_id  = bar_id
      coworker.user_id = user_id
      coworker.save! 
      return true
    else
      return false
    end
  end
end
